package cn.wangkai.peanut.db.mod;

import java.io.Serializable;
import java.math.BigDecimal;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.math.NumberUtils;

/**
 * //
//	public Boolean updateNewProduct(String ProductID,String ADID,String ProductURL,Product product) throws SQLException {
//		MyDbutil mydbutil = MyDbutil.Open();
//		Connection conn = mydbutil.getConnection();
//		PreparedStatement stmt = null;
//		ResultSet rs = null;
//		int newproductID = 0;
//		int oldproductID = 0;
//		QueryRunner qr = new QueryRunner();
//		conn.setAutoCommit(false);
//		try {
//			oldproductID = DbTools.StrToInt(ProductID);
//			Object[] params = new Object[2];
//			params[0] = ProductURL+"_OLD";
//			params[1] = oldproductID;
//			qr.update(conn, "update product set producturl=? where productID=?", params);
//			stmt = conn.prepareStatement("insert into product (ADOwnerID,industryID,Brandid,Name,Content," +
//					"Producturl,PageEncode,PageHtml,Adcount,putCount)values(?,?,?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS);
//			stmt.setInt(1, product.getAdownerid());
//			stmt.setString(2, product.getIndustryid());
//			if(product.getBrandid()==0)
//				stmt.setString(3, null);
//			else
//				stmt.setInt(3, product.getBrandid());
//			stmt.setString(4, product.getName());
//			stmt.setString(5, product.getContent());
//			stmt.setString(6, product.getProducturl());
//			stmt.setString(7, product.getPageencode());
//			stmt.setString(8, product.getPagehtml());
//			stmt.setInt(9, 0);
//			stmt.setInt(10, 0);
//			stmt.executeUpdate();
//			rs = stmt.getGeneratedKeys();
//			if(rs.next())
//				newproductID = rs.getInt(1);
//			params = new Object[2];
//			params[0] = newproductID;
//			params[1] = DbTools.StrToInt(ADID);
//			qr.update(conn,"update addetail set productID=? WHERE ADID=?",params);
//			conn.commit();
//		} catch (SQLException e) {
//			conn.rollback();
//			e.printStackTrace();
//			return false;
//		} finally {
//			conn.setAutoCommit(true);
//			DbUtils.close(rs);
//			DbUtils.close(stmt);
//			DbUtils.close(conn);
//		}
//		return true;
//	}
	
 * @author Administrator
 *
 */

@Slf4j
public class GeneratedKey implements Serializable {

	private static final long serialVersionUID = 835107404897153470L;
	private long UpdateNum=0L;
	private Object GeneratedKey=null;
	
	
	public long getUpdateNum() {
		return UpdateNum;
	}

	public void setUpdateNum(long updateNum) {
		UpdateNum = updateNum;
	}

	public Object getGeneratedKey() {
		return GeneratedKey;
	}

	public Long getLongKey(){
		if(GeneratedKey == null) return null;
		if(GeneratedKey instanceof Long){
			return (Long)GeneratedKey;
		}else if(GeneratedKey instanceof Integer){
			return ((Integer)GeneratedKey).longValue();
		}else if(GeneratedKey instanceof BigDecimal){
			return ((BigDecimal)GeneratedKey).longValue();
		}else{
			return NumberUtils.toLong(String.valueOf(GeneratedKey));
		}
	}
	
	public Integer getIntegerKey(){
		if(GeneratedKey == null) return null;
		if(GeneratedKey instanceof Long){
			return ((Long)GeneratedKey).intValue();
		}else if(GeneratedKey instanceof Integer){
			return ((Integer)GeneratedKey);
		}else if(GeneratedKey instanceof BigDecimal){
			return ((BigDecimal)GeneratedKey).intValue();
		}else{
			return NumberUtils.toInt(String.valueOf(GeneratedKey));
		}
	}
	
	public BigDecimal getBigDecimalKey(){
		if(GeneratedKey == null) return null;
		if(GeneratedKey instanceof Long){
			return new BigDecimal((Long)GeneratedKey);
		}else if(GeneratedKey instanceof Integer){
			return new BigDecimal((Integer)GeneratedKey);
		}else if(GeneratedKey instanceof BigDecimal){
			return (BigDecimal)GeneratedKey;
		}else{
			return new BigDecimal(String.valueOf(GeneratedKey));
		}
	}
	
	public void setGeneratedKey(Object generatedKey) {
		GeneratedKey = generatedKey;
	}

	public GeneratedKey() {
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	}

}
